package com.chenzhou.qx.oaid;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;

/**
 * @author tk
 * @date 2020/3/14
 */
public class PermissionChecker {

    public static final String TAG = PermissionChecker.class.getSimpleName();
    public static final int READ_PHONE_STATE = 1;

    private static PermissionChecker checker;

    private PermissionChecker(){
    }

    public static PermissionChecker getInstance(){
        if (checker == null){
            checker = new PermissionChecker();
        }
        return checker;
    }

    public void requestReadPhoneState(Activity activity) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            return ;
        }

        int hasWriteContactsPermission = activity.checkSelfPermission(Manifest.permission.READ_PHONE_STATE);
        if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) {
            activity.requestPermissions(new String[] {Manifest.permission.READ_PHONE_STATE}, READ_PHONE_STATE);
        }
    }

}
